package cn.sytton.taffe.log.controller;

import cn.sytton.taffe.log.constants.AccessSource;
import cn.sytton.taffe.log.entity.UserLogEntity;
import cn.sytton.taffe.log.service.IUserLogService;
import com.github.pagehelper.PageInfo;
import cn.sytton.taffe.framework.base.controller.BaseController;
import cn.sytton.taffe.framework.base.entity.PageParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 用户操作日志控制层
 *
 * @author skyrock
 */
@Tag(name = "用户操作日志")
@RestController
@RequiredArgsConstructor
@RequestMapping("/log/user")
public class UserLogController extends BaseController {

    private final IUserLogService userLogService;

    @Operation(summary = "添加PC端用户操作日志")
    @PostMapping("/pc")
    public void create(@RequestBody UserLogEntity entity) {
        entity.setAccessSource(AccessSource.pc.name());
        userLogService.create(entity);
    }

    @Operation(summary = "查询分页访问日志列表")
    @Parameter(name = "pp", description = "分页参数对象", in = ParameterIn.QUERY, required = true)
    @GetMapping
    public PageInfo<UserLogEntity> findPage(PageParam pp) {
        return userLogService.findListPageOfXml(pp);
    }

}
